<template>
  <ul class="song-list">
    <li class="item" v-for="(song,index) in songs" :key="song.id"
    @click="selectItem(song,index)">
      <div class="rank" v-if="rank">
          <span>{{index+1}}</span>
      </div>
      <div class="content">
        <h2 class="name">{{ song.name }}</h2>
        <p class="desc">{{ getDesc(song) }}</p>
      </div>
    </li>
  </ul>
</template>
<script>
export default {
  name: 'SongList',
  props: {
    songs: {
      type: Array,
      default: () => []
    },
    rank: {
      type: Boolean,
      default: false
    }
  },
  emits: ['select'],
  methods: {
    getDesc (song) {
      return `${song.singer}.${song.album}`
    },
    selectItem (song, index) {
      this.$emit('select', { song, index })
    }
  }
}
</script>
<style lang="scss" scoped>
.song-list {
  .item {
    display: flex;
    align-items: 'center';
    box-sizing: border-box;
    height: 2.729211rem;
    font-size: $font-size-medium;
  }
  .rank {
        flex: 0 0 1.066098rem;
        width: 1.066098rem;
        margin-right: .852878rem;
        margin-top: .16322rem;
        text-align: center;
        .text {
          color: $color-theme;
          font-size: $font-size-large;
        }
  }
  .content {
    flex: 1;
    line-height: 0.852878rem;
    overflow: hidden;
    .name {
      @include no-wrap();
      color: $color-text;
    }
    .desc {
      @include no-wrap();
      margin-top: 0.170576rem;
      color: $color-text-d;
    }
  }
}
</style>
